<template>
  <div class="app-container">
    <el-card class="box-card">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="手牌号" prop="handBrand">
        <el-input
          v-model="queryParams.handBrand"
          placeholder="请输入手牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="entryName">
        <el-input
          v-model="queryParams.entryName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item style="float: right">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
<br><br>
    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >退单</el-button>
      </el-col>

<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>

    <el-table v-loading="loading" :data="detailsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"  />
<!--      <el-table-column label="id" align="center" prop="id" />-->
      <el-table-column label="手牌号" align="center" prop="handBrand" />
      <el-table-column label="项目名称" align="center" prop="entryName" />
      <el-table-column label="手牌类别" align="center" prop="handCategory">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yqg_hand_category" :value="scope.row.handCategory"/>
        </template>
      </el-table-column>
      <el-table-column label="入店时间" align="center" prop="openingTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.openingTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目类别" align="center" prop="projectCategory">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yqg_project_category" :value="scope.row.projectCategory"/>
        </template>
      </el-table-column>
      <el-table-column label="数量" align="center" prop="quantity" />


    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    </el-card>
    <br>
    <el-button class="right" style="float: right;margin-top: 10px;margin-bottom: 15px" @click="cancel1" >返回</el-button>
    <br>
    <!-- 添加或修改消费详细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="退单时间"  prop="chargebackTime">
          <el-date-picker clearable
                          style="width: 100%"
                          v-model="form.chargebackTime"
                          type="date"
                          value-format="yyyy-MM-dd "
                          readonly="true">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="退单数量" prop="note7">

          <el-input v-model="form.note7" placeholder="请输入退单数量"  clearable      />
        </el-form-item>
        <el-form-item label="退单原因" prop="reasonForChargeback">

            <el-input v-model="form.reasonForChargeback" placeholder="请输入退单原因"  clearable      />
          </el-form-item>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
  import { listDetails, getDetails, delDetails, addDetails, updateDetails,getgoods } from "@/api/module/lys/details";

  export default {
    name: "Details",
    props: ['tuidanhandid'], // 接收传入的 id
    dicts: ['yqg_hand_category', 'yqg_hand_state', 'yqg_payment_method', 'yqg_consumption_status', 'yqg_retention_status', 'yqg_project_category', 'yqg_post', 'yqg_check_out_status', 'yqg_department', 'yqg_merge_status', 'yqg_sailings_signs', 'yqg_next_clock_status'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 消费详细表格数据
        detailsList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userId: null,
          deptId: null,
          department: null,
          nickName: null,
          userName: null,
          post: null,
          handBrand: null,
          handCategory: null,
          handState: '1',
          retentionStatus: null,
          mergeStatus: null,
          openingTime: null,
          drawTime: null,
          mergeHands: null,
          mergeBarBillsId: null,
          leaveTime: null,
          beforeLeave: null,
          beforeBarBillsId: null,
          entryName: null,
          projectCategory: null,
          projectCode: null,
          mnemonicCode: null,
          unit: null,
          unitPrice: null,
          commissionPrice: null,
          together: null,
          sailingsSigns: null,
          barBillsId: null,
          recordingTime: null,
          quantity: null,
          totalAmount: null,
          seat: null,
          orderNumber: null,
          paymentMethod: null,
          consumptionStatus: 0,
          chargebackTime: null,
          reasonForChargeback: null,
          chargebackProcessorAccount: null,
          chargebackProcessorName: null,
          clockTime: null,
          nextClockTime: null,
          nextClockStatus: null,
          recordEmployeeNumber: null,
          recorderEmployeeName: null,
          roomType: null,
          openingHours: null,
          checkOutTime: null,
          checkOutStatus: null,
          note1: null,
          note2: null,
          note3: null,
          note4: null,
          note5: null,
          note6: null,
          note7: null,
          note8: null,
          note9: null,
          note10: null
        },
        // 表单参数
        form: {
          chargebackTime:this.getNowTime()

        },
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      if(this.tuidanhandid){
        this.queryParams.handBrand=this.tuidanhandid[0];
      }
      this.getList();
      this.getNowTime();
    },
    //必须写监听，不然会出现id还是还是上一次的问题
    watch: {
      tuidanhandid() {
        // 当 id 值发生改变时，重新获取或者刷新数据
        if(this.tuidanhandid){
          this.queryParams.handBrand=this.tuidanhandid[0];
        }
        this.getList();
        this.getNowTime();
      },
    },
    methods: {

      /** 查询消费详细列表 */
      getList() {
        this.loading = true;
        listDetails(this.queryParams).then(response => {
          this.detailsList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel1() {
        this.$emit("closeDialog"); // 触发 closeDialog 事件
      },
      // 取消按钮
      cancel() {
       this.open=false;
       this.reset();
      },
      getNowTime() {
        var now = new Date();
        var year = now.getFullYear(); //得到年份
        var month = now.getMonth(); //得到月份
        var date = now.getDate(); //得到日期
        month = month + 1;
        month = month.toString().padStart(2, "0");
        date = date.toString().padStart(2, "0");
        var defaultDate = `${year}-${month}-${date}`;
        return defaultDate;
    },
      // 表单重置
      reset() {
        this.form = {
          ID: null,
          userId: null,
          deptId: null,
          department: null,
          nickName: null,
          userName: null,
          post: null,
          handBrand: null,
          handCategory: null,
          handState: null,
          retentionStatus: null,
          mergeStatus: null,
          openingTime: null,
          drawTime: null,
          mergeHands: null,
          mergeBarBillsId: null,
          leaveTime: null,
          beforeLeave: null,
          beforeBarBillsId: null,
          entryName: null,
          projectCategory: null,
          projectCode: null,
          mnemonicCode: null,
          unit: null,
          unitPrice: null,
          commissionPrice: null,
          together: null,
          sailingsSigns: null,
          barBillsId: null,
          recordingTime: null,
          quantity: null,
          totalAmount: null,
          seat: null,
          orderNumber: null,
          paymentMethod: null,
          consumptionStatus: null,
          chargebackTime: null,
          reasonForChargeback: null,
          chargebackProcessorAccount: null,
          chargebackProcessorName: null,
          clockTime: null,
          nextClockTime: null,
          nextClockStatus: null,
          recordEmployeeNumber: null,
          recorderEmployeeName: null,
          roomType: null,
          openingHours: null,
          checkOutTime: null,
          checkOutStatus: null,
          note1: null,
          note2: null,
          note3: null,
          note4: null,
          note5: null,
          note6: null,
          note7: null,
          note8: null,
          note9: null,
          note10: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加消费详细";
      },
      /** 修改按钮操作 */
      handleUpdate() {
        this.reset();
        this.open = true;
        this.title = "退单操作";
      /*    updateDetails(this.form).then(response => {
            this.$modal.msgSuccess("退单成功");
            this.open = false;
            this.getList();
          });*/
      this.form.chargebackTime=this.getNowTime()

      },
      /** 提交按钮 */
      submitForm(row) {


        const ids = row.id || this.ids;
      const dataaaa=this.form.reasonForChargeback;
      const note7=this.form.note7;
        getgoods(ids,dataaaa,note7).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.open = false;
          this.getList();
        });



      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const IDs = row.ID || this.ids;
        this.$modal.confirm('是否确认删除消费详细编号为"' + IDs + '"的数据项？').then(function() {
          return delDetails(IDs);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },

      /** 导出按钮操作 */
      handleExport() {
        this.download('project/details/export', {
          ...this.queryParams
        }, `details_${new Date().getTime()}.xlsx`)
      }
    }

  }
</script>
